package profiles;

import gestures.slideGestures.SlideGestureChange;

import java.awt.AWTException;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;
import java.awt.geom.Point2D.Float;

import services.GestureClient;
import services.subscribers.GestureEventArgs;

public class TestProfile extends BaseApplicationProfile {

	Robot robot;
	
	int width;
	int height;
	
	public TestProfile(GestureClient gl) {
		super(gl);
		// TODO Auto-generated constructor stub
		

		GraphicsEnvironment ge = GraphicsEnvironment.
		   getLocalGraphicsEnvironment();
		   GraphicsDevice[] gs = ge.getScreenDevices();
		
		width = gs[0].getDisplayMode().getWidth();
		height = gs[0].getDisplayMode().getHeight();   
		   
		try {
			robot = new Robot();
		} catch (AWTException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	
	
	public void gestureEvent_DraggingGesture(Object source, GestureEventArgs e ) {
		slideGestureDelegate_OnSlideChange(source, e);
	}
	
	public void slideGestureDelegate_OnSlideChange(Object source,
			GestureEventArgs e) {
		// TODO Auto-generated method stub
		
		
		
		
		if (e.getGesture() != null && e.getGesture().getClass().equals(SlideGestureChange.class)) {
			SlideGestureChange slide = (SlideGestureChange) e.getGesture();
			
			Float coords = slide.getGestureCoords()[0];
			
			//System.out.println( "coords:" + coords);
			
			robotMouseMove(coords);
		}
	}



	public void robotMouseMove(Float coords) {
		if( robot != null ) {
			robot.mouseMove((int)((double)width * coords.x), 
							(int)((double)height * coords.y));
		}
	}



	@Override
	public void tapGestureDelegate_OnTap(Object source, GestureEventArgs e) {
		// TODO Auto-generated method stub
		super.tapGestureDelegate_OnTap(source, e);
		
		robotMouseMove(e.getGesture().getGestureCoords()[0]);
	}
	
	

}
